package guij.controller.subscriber;


import java.util.HashMap;
import java.util.Map;

import guij.dao.mapper.SubscriberMapper;
import guij.dao.vo.Subscriber;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;
//验证订阅mail的 真实性
public class AuthMailSub implements Controller{

	@Override
	public ModelAndView handleRequest(HttpServletRequest arg0,
			HttpServletResponse arg1) throws Exception {
		if(arg0.getParameter("mail")!=null&&
		   arg0.getParameter("clientKey")!=null&&
		   arg0.getParameter("id")!=null){
		
			int mailID =Integer.parseInt(arg0.getParameter("di"));
			String mail = arg0.getParameter("mail");
			String clientKey = arg0.getParameter("clientKey");
			int ret = subscriberMapper.auth(mail,clientKey);
			Map retMap = new HashMap();
			retMap.put("ret", ret);
			if(ret>0){
				//auth sucessed;
				Subscriber subscriber = subscriberMapper.getSub(mailID);
				retMap.put("subscriber",subscriber);
			}else{
				//auth fiald			
			}
			return new ModelAndView(getViewPage(),retMap);
		}
		
		return null;
	}

	
	
	private String ViewPage;
	public String getViewPage() {
		return ViewPage;
	}

	public void setViewPage(String viewPage) {
		ViewPage = viewPage;
	}



	private SubscriberMapper subscriberMapper;

	public SubscriberMapper getSubscriberMapper() {
		return subscriberMapper;
	}

	public void setSubscriberMapper(SubscriberMapper subscriberMapper) {
		this.subscriberMapper = subscriberMapper;
	}


}
